package com.example.node.message;

import com.example.node.config.NodeConfig;
import com.example.node.utils.IdUtils;

import java.io.Serializable;

/*
 * @className: Request
 * @author: chentao
 * @date: 2025/10/25 下午5:21
 * @Version: 1.0
 * @description:
 */
public class Request implements Serializable {

    private String requestId;

    private long requestTime;

    private long senderId;

    private NodeConfig senderConfig;

    private long receiverId;

    private long timeout = 5000;

    private Object message;

    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public long getRequestTime() {
        return requestTime;
    }

    public void setRequestTime(long requestTime) {
        this.requestTime = requestTime;
    }

    public long getSenderId() {
        return senderId;
    }

    public void setSenderId(long senderId) {
        this.senderId = senderId;
    }

    public long getReceiverId() {
        return receiverId;
    }

    public void setReceiverId(long receiverId) {
        this.receiverId = receiverId;
    }

    public long getTimeout() {
        return timeout;
    }

    public void setTimeout(long timeout) {
        this.timeout = timeout;
    }

    public Object getMessage() {
        return message;
    }

    public void setMessage(Object message) {
        this.message = message;
    }

    public NodeConfig getSenderConfig() {
        return senderConfig;
    }

    public void setSenderConfig(NodeConfig senderConfig) {
        this.senderConfig = senderConfig;
        this.senderId = senderConfig.getServerId();
    }

    public Request(long receiverId, Object message) {
        this.receiverId = receiverId;
        this.message = message;
        this.requestId = IdUtils.getId();
        this.requestTime = System.currentTimeMillis();
    }

    public Request(Object message) {
        this.message = message;
        this.requestId = IdUtils.getId();
        this.requestTime = System.currentTimeMillis();
    }
}
